package com.hengda.museumonline.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hengda.museumonline.R;
import com.hengda.museumonline.entity.ExhibitionBean;
import com.hengda.museumonline.ui.MuseumContentActivity;

import static com.yolanda.nohttp.NoHttp.getContext;

/**
 * @author：JFWU on 2016/9/26 18:36
 * @E-mail：jeffy12138@126.com
 */
public class NoticeAdapter extends RecyclerView.Adapter<NoticeAdapter.ListHolder> {
    private Context context;
    private ExhibitionBean exhibitionBean;

    public NoticeAdapter(Context context, ExhibitionBean exhibitionBean) {
        this.context = context;
        this.exhibitionBean = exhibitionBean;
    }

    @Override
    public NoticeAdapter.ListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.exhibition1_pop, parent, false);
        return new ListHolder(view);
    }

    @Override
    public void onBindViewHolder(NoticeAdapter.ListHolder holder, int position) {
        holder.setData(position);
    }

    @Override
    public int getItemCount() {
        return exhibitionBean.getData().get(0).getList().size();
    }

    class ListHolder extends RecyclerView.ViewHolder {
        private TextView title;
        private TextView days;
        private TextView hits;
        private ImageView itemBackground;
        private LinearLayout exhibition1_pop;

        public ListHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.title);
            days = (TextView) itemView.findViewById(R.id.days);
            hits = (TextView) itemView.findViewById(R.id.hits);
            itemBackground = (ImageView) itemView.findViewById(R.id.item_background);
            exhibition1_pop = (LinearLayout) itemView.findViewById(R.id.exhibition1_pop);
        }

        public void setData(final int position) {
            title.setText(exhibitionBean.getData().get(0).getList().get(position).getTitle());
            days.setText(exhibitionBean.getData().get(0).getList().get(position).getDays() + "");
            hits.setText(exhibitionBean.getData().get(0).getList().get(position).getHits());
            Glide.with(getContext()).load(exhibitionBean.getData().get(0).getList().get(position).getItem_background()).into(itemBackground);
            exhibition1_pop.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Bundle bundle = new Bundle();
                    bundle.putString("id", exhibitionBean.getData().get(0).getList().get(position).getId());
                    Intent intent = new Intent(getContext(), MuseumContentActivity.class);
                    intent.putExtras(bundle);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    getContext().startActivity(intent);
                }
            });
        }


    }
}
